var rksh_ys = {
    fillData:function () {
        $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm':'cd'}, function (cddata) {
            $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm':'jzfs'}, function (data) {
                fillHtmxByCgd($.webPath() + '/kcgl/rksh/rksh_cgmx?rksh.id=' + $("[name='rksh.id']").val() || '', cddata, data);
            })
        });
    }
}

//采购单明细
function fillHtmxByCgd(href, cdOptions, fsOptions) {
    $("#rksh_ys_mx").edatagrid({
        url:href,
        fitColumns:false,
        singleSelect:true,
        fit:false,
        height:400,
        checkOnSelect:false,
        selectOnCheck:false,
        rownumbers:true,
        toolbar:"#rksh_cgdmx_toolbar",
        frozenColumns:[
            [
                {field:'wzgg.oldcode', title:'老物资编码', align:'center', hidden:true},
                {field:'wzgg.code', title:'新物资编码', align:'center', width:100, rowspan:2},
                {field:'wzgg.name', title:'物资名称', align:'center', width:50, rowspan:2},
                {field:'wzgg.ggxh', title:'规格型号', align:'center', width:50, rowspan:2},
                {field:'wzgg.th', title:'图号', align:'center', hidden:true},
                {field:'cd.z', title:'产地', width:40, align:'center', rowspan:2},
                {field:'jzfs.z', title:'记重方式', align:'center', width:50, rowspan:2},
//                {field:'dhdStr', title:'到货单', align:'center', width:70, rowspan:2, formatter:dhdUpCell}
//                {field:'jzfs.id', editor:{type:'combobox', options:{
//                    data:fsOptions,
//                    valueField:'id',
//                    textField:'z',
//                    multiple:false,
//                    panelHeight:'55'
//                }
//                }, formatter:function (value) {
//                    for (var i = 0; i < fsOptions.length; i++) {
//                        if (fsOptions[i].id == value) return fsOptions[i].z;
//                    }
//                    return value;
//                }, title:'记重方式', width:50, rowspan:2}
            ]
        ],
        columns:[
            [
                {title:'发货', colspan:2},
                {title:'到货', colspan:2},
                {field:'kh.id', title:'卡号ID', hidden:true},
                {field:'kh.khbm', title:'卡号编码', align:'center', hidden:true},
                {field:'hsj', title:'含税价', width:170, rowspan:2, align:'right',
                    formatter:function (value) {
                        var val = formatJeForHtml(value);
                        return val;
                    }},
                {field:'bhsj', title:'不含税价', width:170, rowspan:2, align:'right',
                    formatter:function (value) {
                        var val = formatJeForHtml(value);
                        return val;
                    }}
            ],
            [

                {field:'js', title:'件数', precision:4, width:100, align:'right'},
                {field:'sbsl', title:'重量', precision:4, width:150, align:'right',
                    formatter:function (value) {
                        var val = formatSlForHtml(value);
                        return val;
                    }},
                {field:'rkjs', title:'件数', precision:4, width:100, align:'right'},
//                {field:'rkjz', title:'件重', precision:4, width:100, align:'right'},
                {field:'rksl', title:'重量', align:'right', precision:4, width:100}
//                {field:'rkjs', title:'件数', width:100, editor:{type:'numberbox'}},
//                {field:'rkjz', title:'件重', width:100, editor:{type:'numberbox'}},
//                {field:'rksl', title:'数量', width:200, editor:{type:'numberbox', options:{min:0, precision:4}},
//                    formatter:function (value) {
//                        var val = formatSlForHtml(value);
//                        return val;
//                    }}
            ]
        ],
        loadFilter:function (data) {
            $.each(data.rows, function () {
                this['rksl'] = this.sssl;
                this['rkjs'] = this.ssjs;
            })
            return data;
        }
    })

}

$(function () {
    $("#rksh_fhgs_id").xsqyjgcombobox($("#rksh_gys_id").val());

    rksh_ys.fillData();

    //全部验收按钮触发
    $('#btn_rkshMx_allSave_ys').click(function () {
        $("#rksh_ys_Form").form('submit', {
            url:$.webPath() + "/kcgl/rksh/check_rksh",
            onSubmit:function (param) {
                $.extend(param, {"rksh.fhgs.id":$("[name='rksh.fhgs.id']").val()});
            },
            success:function (data) {
                var obj = eval('(' + data + ')');
                if (obj.statusCode == '200') {
                    $(rksh.win_rkys).window('close');
                    $('#grid_rksh').datagrid('reload');
//                    $('#layout_rksh').layout('panel', 'center').panel('refresh');
                    $.messager.show({title:'提示框', msg:obj.message, timeout:3000, showType:'slide'});
                } else {
                    $.messager.alert('提示', obj.message, 'info');
                }
            }
        });
    });
});


//$(function () {
//    rksh_ys.fillData();
//    setTimeout(function () {
//        $('#rksh_ys_tabs').tabs('select', "入库明细");
//    }, 100);
//
//    //全部验收按钮触发
//    $('#btn_rkshMx_allSave_ys').click(function () {
//        $('#rksh_ys_mx').edatagrid('acceptChanges');
//        var rk_datas = $('#rksh_ys_mx').edatagrid('getData');
//        var errorIndex = "";
//        $.each(rk_datas.rows, function (i, val) {
//            if (val.sbsl != val.rksl) {
//                errorIndex += (i + 1) + ',';
//            }
//        })
//        errorIndex = errorIndex.substring(0, errorIndex.length - 1);
//        if (errorIndex != "") {
//            $.messager.confirm('确认', '第' + (errorIndex) + '行的到货数量与发货数量不符是否要继续入库', function (r) {
//                if (r) {
//                    rksh_stock();
//                }
//            });
//        } else {
//            rksh_stock();
//        }
//    });
//
//})

//全部入库调用方法
//function rksh_stock() {
//    $("#rksh_ys_mx").edatagrid('saveRow');
//    $("#rksh_cgd_Form").form('submit', {
//        url:$.webPath() + "/kcgl/rksh/stock_rksh",
//        onSubmit:function (param) {
//            var data = $('#rksh_ys_mx').edatagrid("getData");
//            if (!data.rows.length) {
//                $('#rksh_cgd_Form').tabs('select', "采购明细");
//                $.messager.alert("提示", "采购明细需要填写!", "waring");
//                return false;
//            }
//            var arrayPrefix = 'rksh.cgdmxList';
//            //物资计划明细
//            var paramString = "{";
//            //物资计划明细
//            for (var i = 0; i < data.rows.length; i++) {
//                if (data.rows[i].sbsl != 0 && data.rows[i].rksl == 0) {
//                    $.messager.alert('提示', '第' + (i + 1) + '行的入库数量不能为0', 'info');
//                    return false;
//                }
//                {
//                    var objectString = $.toJSONStringSubPrefix(data.rows[i], arrayPrefix + "[" + i + "].",
//                        [
//                            'id',
//                            ['wzgg.id', 'gg.id'],
//                            'cd.id',
//                            'jzfs.id',
//                            'hsj',
//                            'bhsj',
//                            'bz',
//                            'sbsl',
//                            'js',
//                            'rksl',
//                            'rkjs',
//                            'rkjz',
//                            ['kh.id', 'kh.id']
//                        ]);
//                    paramString = paramString + objectString.substring(1, objectString.length - 1) + ",";
//                }
//            }
//            if (data.rows && data.rows.length > 0)
//                paramString = paramString.substring(0, paramString.length - 1);
//            paramString += "}";
//            $.extend(param, $.parseJSON(paramString));
//            return $(this).form('validate');
//        },
//        success:function (data) {
//            var obj = eval('(' + data + ')');
//            if (obj.statusCode == '200') {
//                $(rksh.win_rksh).window('close');
//                $('#grid_rksh').datagrid('reload');
//                $('#layout_rksh').layout('panel', 'center').panel('refresh');
//                $.messager.show({title:'提示框', msg:obj.message, timeout:3000, showType:'slide'});
//            } else {
//                $.messager.alert('提示', obj.message, 'info');
//            }
//        }
//    });
//}


